package gold.digger;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC845 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int longestMountain(int[] A) {
            int N = A.length;
            int ans = 0, base = 0;
            while (base < N) {
                int end = base;
                // if base is a left-boundary
                if (end + 1 < N && A[end] < A[end + 1]) {
                    // set end to the peak of this potential mountain
                    while (end + 1 < N && A[end] < A[end + 1]) end++;

                    // if end is really a peak..
                    if (end + 1 < N && A[end] > A[end + 1]) {
                        // set end to the right-boundary of mountain
                        while (end + 1 < N && A[end] > A[end + 1]) end++;
                        // record candidate answer
                        ans = Math.max(ans, end - base + 1);
                    }
                }

                base = Math.max(end, base + 1);
            }

            return ans;
        }
    }


    public void run() {
        Solution solution = new Solution();
        List<Integer> list = new ArrayList<>();
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC845 an = new LC845();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
